import { Inject, Injectable } from '../decorators/inject';
import { NCellRender } from '../types/cell-render.interface';
import { TableEvent } from './table-event';
import { TableDatas } from './table-datas';
type EditorConstructor = {new(...args: any[]):NCellRender.AEdit};
@Injectable('CellRenderEditManage')
export class CellRenderEditManage {
    
    protected cellRenderEditMap: Map<string, {render: NCellRender.ARender, editor: {new():NCellRender.AEdit}}> = new Map();
    constructor(
        protected tableEvent: TableEvent,
        protected datas: TableDatas
    ) {

    }
    public init() {
        
    }
    public register(type: string, render: {new():NCellRender.ARender}, editor: EditorConstructor) {
        editor.prototype.valueChange = (row: number, col: number, value: any) => {

        }
        this.cellRenderEditMap.set(type, {render: new render(), editor: editor});
    }
    public getRender(type: string): NCellRender.ARender | null {
        let temp = this.cellRenderEditMap.get(type);
        if(temp === undefined) {
            console.error(`can't find cell type render: ${type}`);
            return null;
        }
        return temp.render;
    }
    public getEditor(type: string): {new(row: number, col: number):NCellRender.AEdit} | null {
        let temp = this.cellRenderEditMap.get(type);
        if(temp === undefined) {
            console.error(`can't find cell type editor: ${type}`);
            return null;
        }
        return temp.editor;
    }
}